Rewrite the update logic to a more direct form, improving readability by
removing the manual iteration and list manipulation.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4101>
this.emit('current-source-changed', oldSource);
- for (let i = 1; i < this._mruSources.length; ++i) {
- if (this._mruSources[i] === newSource) {
- const currentSource = this._mruSources.splice(i, 1);
- this._mruSources = currentSource.concat(this._mruSources);
- break;
- }
- }
+ this._mruSources = [
+ newSource,
+ ...this._mruSources.filter(s => s !== newSource),
+ ];
+
this._changePerWindowSource();
}